package biz

import (
	v1 "activity/api/activity/v1"
	"activity/pkg"
	"context"
	hello_stu "helloworld/api/student/v1"

	"github.com/go-kratos/kratos/v2/errors"
	"github.com/go-kratos/kratos/v2/log"
)

var (
	// ErrUserNotFound is user not found.
	ErrUserNotFound = errors.NotFound(v1.ErrorReason_USER_NOT_FOUND.String(), "user not found")
)

type Greeter struct {
	Hello string
}

// 不需要model处理 就不写了
type ActivityRepo interface {
}

type ActivityBiz struct {
	//repo ActivityRepo
	log    *log.Helper
	stuRpc hello_stu.StudentServiceClient
}

// NewActivityBiz new a Greeter usecase.
func NewActivityBiz(logger log.Logger, stuRpc hello_stu.StudentServiceClient) *ActivityBiz {
	return &ActivityBiz{
		log:    log.NewHelper(logger),
		stuRpc: stuRpc,
	}
}

// 获取学生
func (uc *ActivityBiz) GetStudent(ctx context.Context, req *v1.GetStuRequest) (*v1.GetStuReply, error) {

	// 构建RPC请求
	getStuReq := &hello_stu.ListStudentRequest{
		PageNum:  req.PageNum,
		PageSize: req.PageSize,
	}

	// 调用RPC接口 获取学生数据
	ret, err := uc.stuRpc.ListStudent(ctx, getStuReq)
	if err != nil {
		return nil, err
	}

	// 转类型
	reply := v1.GetStuReply{}
	errCopyTo := pkg.CopyTo(&ret.StudentList, &reply.StudentList)
	if errCopyTo != nil {
		return nil, errCopyTo
	}
	return &reply, nil
}
